﻿using UnityEngine;
using System.Collections;

public class PlayerScript : MonoBehaviour {
	
	//public float speed = 0.1f;
	private bool jumping = false;
	private bool jumpDirUp = true;

	public int prevID = -1;

	void Update () {
		if (Input.touchCount > 0 && 
				Input.GetTouch (0).phase == TouchPhase.Moved) {

			Vector3 touchDeltaPosition = Camera.main.ScreenToWorldPoint (Input.GetTouch (0).position);  
			touchDeltaPosition.z = transform.position.z;
			transform.position = Vector3.Lerp (transform.position, touchDeltaPosition, 7 * Time.deltaTime);
		}
		if(Input.GetTouch (0).phase == TouchPhase.Ended){
			jumping = true;
		}
		/*else {
			Vector3 touchDeltaPosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);  
			touchDeltaPosition.z = transform.position.z;
			transform.position = Vector3.Lerp (transform.position, touchDeltaPosition, 7 * Time.deltaTime);
		}
		
		if (Input.GetButtonDown ("Fire1")) {
			jumping = true;
		}*/
		jump ();
	}

	void jump(){
		if (jumping) {
			if(jumpDirUp){
				transform.localScale = Vector3.Lerp (transform.localScale, new Vector3(1, 1, 1), 6 * Time.deltaTime);
				if(transform.localScale.x > 0.95f){
					jumpDirUp = false;
				}
			}else{
				transform.localScale = Vector3.Lerp (transform.localScale, new Vector3(0.5f, 0.5f, 1), 6 * Time.deltaTime);
				if(transform.localScale.x < 0.55f){
					jumping = false;
					jumpDirUp = true;
				}
			}
		}
	}

	public bool isInAir(){
		return jumping;
	}
}
